package com.lv.service.room.helper

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lv.service.bean.AddressDetailsBean
import com.lv.service.bean.AttributeBean
import com.lv.service.bean.BperiodsBean
import com.lv.service.bean.CategoryMoreBean
import com.lv.service.bean.CertificationBean
import com.lv.service.bean.ConditionBean
import com.lv.service.bean.ContactBean
import com.lv.service.bean.ContractBean
import com.lv.service.bean.DescribesBean
import com.lv.service.bean.DisplayFacBean
import com.lv.service.bean.DisplayPro
import com.lv.service.bean.EwmsBean
import com.lv.service.bean.Sku
import com.lv.service.bean.SpecitemsBean
import com.lv.service.bean.SpuItemBean
import com.lv.service.bean.TelSecondCategory
import com.lv.service.room.category.CategoryBean

/**
 * 作者： ygx
 * 创建日期：2022/7/28 10:57 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class InspectionCategoryScoundConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<TelSecondCategory>? {
        val listType = object : TypeToken<List<TelSecondCategory>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<TelSecondCategory>?): String? {
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCategoryConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<CategoryBean>? {
        val listType = object : TypeToken<List<CategoryBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<CategoryBean>?): String? {
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayContactConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<ContactBean>? {
        val listType = object : TypeToken<List<ContactBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<ContactBean>?): String? {
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayCertificationConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<CertificationBean>? {
        val listType = object : TypeToken<List<CertificationBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<CertificationBean>?): String? {
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayDisplayFacConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<DisplayFacBean>? {
        val listType = object : TypeToken<List<DisplayFacBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<DisplayFacBean>?): String? {
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayCategoryMoreConverter {
    @TypeConverter
    fun stringToObject(value: String?): CategoryMoreBean? {
        val listType = object : TypeToken<CategoryMoreBean>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: CategoryMoreBean?): String? {
        if (list == null) {
            return null
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayDisplayProConverter {
    @TypeConverter
    fun stringToObject(value: String?): DisplayPro? {
        val listType = object : TypeToken<DisplayPro>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: DisplayPro?): String? {
        if (list == null) {
            return null
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionCompnayBperiodsBeanConverter {
    @TypeConverter
    fun stringToObject(value: String?): BperiodsBean? {
        val listType = object : TypeToken<BperiodsBean>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: BperiodsBean?): String? {
        if (list == null) {
            return null
        }
        val gson = Gson()
        return gson.toJson(list)
    }

}

class InspectionConditionConverter {
    @TypeConverter
    fun stringToObject(value: String?): ConditionBean {
        val listType = object : TypeToken<ConditionBean>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: ConditionBean?): String {
        val gson = Gson()
        if (list == null) {
            val con = ConditionBean("0", "0", "0")
            return gson.toJson(con)
        }
        return gson.toJson(list)
    }

}

class InspectionEwmsConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<EwmsBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<EwmsBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<EwmsBean>?): String? {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }
}

class InspectionAddressDetailConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<AddressDetailsBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<AddressDetailsBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<AddressDetailsBean>?): String? {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionSpuConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<SpuItemBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<SpuItemBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<SpuItemBean>?): String? {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionGoodsSkuConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<Sku>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<Sku>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<Sku>?): String {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionGoodDescribesConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<DescribesBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<DescribesBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<DescribesBean>?): String {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionGoodAttributeConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<AttributeBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<AttributeBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<AttributeBean>?): String {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionSpecitemsBeanConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<SpecitemsBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<SpecitemsBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<SpecitemsBean>?): String {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}

class InspectionContractConverter {
    @TypeConverter
    fun stringToObject(value: String?): List<ContractBean>? {
        if (value == null || value == "[]") return emptyList()
        val listType = object : TypeToken<List<ContractBean>>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun objectToString(list: List<ContractBean>?): String {
        val gson = Gson()
        if (list.isNullOrEmpty()) {
            return "[]"
        }
        return gson.toJson(list)
    }

}